/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SwitchFrame.java
 *
 * Created on 07.02.2011, 18:53:35
 */

package ru.staf.SnmpTopologyExplorer.GUI;

import javax.swing.DefaultListModel;
import ru.staf.SnmpTopologyExplorer.FilePseudoAgent;
import ru.staf.SnmpTopologyExplorer.SnmpAgent;
import ru.staf.SnmpTopologyExplorer.GenericAgent;

/**
 *
 * @author aezhov
 */
public class SwitchBase extends javax.swing.JFrame {
    DefaultListModel listModel = new DefaultListModel();
    FilePseudoAgent currentFileAgent = null;
    SnmpAgent currentSnmpAgent = null;
    int currentIndex = -1;

    /** Creates new form SwitchFrame */
    public SwitchBase() {
        initComponents();
        setSNMPpartEnabled(false);
        setDumpFilePartDisabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        selectorCbSNMP = new javax.swing.JCheckBox();
        selectorSNMPWalkDump = new javax.swing.JCheckBox();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        boxSNMPVersion = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        fieldCommunityName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        fieldNetworkName = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        fieldFilename = new javax.swing.JTextField();
        buttonFileSelect = new javax.swing.JButton();
        buttonOK = new javax.swing.JButton();
        buttonCancel = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        buttonAddSwitch = new javax.swing.JButton();
        buttonCancelSwitch = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 12));
        jLabel1.setText("Источник данных по портам");

        selectorCbSNMP.setText("SNMP");
        selectorCbSNMP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectorCbSNMPActionPerformed(evt);
            }
        });

        selectorSNMPWalkDump.setText("Дамп SNMPWalk");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel2.setText("Версия");

        boxSNMPVersion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "v1", "v2c", "v2p", "v2u", "v3" }));

        jLabel3.setText("Community name");

        jLabel4.setText("Сетевое имя или IP адрес");

        jLabel5.setText("Имя файла с дампом");

        buttonFileSelect.setText("Выбрать ...");

        buttonOK.setText("Готово");

        buttonCancel.setText("Убрать");

        jList1.setModel(listModel);
        jScrollPane1.setViewportView(jList1);

        buttonAddSwitch.setText("Добавить");
        buttonAddSwitch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAddSwitchActionPerformed(evt);
            }
        });

        buttonCancelSwitch.setText("Убрать");
        buttonCancelSwitch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelSwitchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(jLabel1)
                        .addGap(132, 132, 132))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(buttonOK)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(fieldNetworkName)
                                .addComponent(selectorCbSNMP, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(boxSNMPVersion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(fieldCommunityName, javax.swing.GroupLayout.Alignment.LEADING)))
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 6, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(selectorSNMPWalkDump)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(fieldFilename, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(buttonFileSelect)
                            .addComponent(buttonCancel))
                        .addGap(34, 34, 34)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(buttonAddSwitch)
                        .addGap(18, 18, 18)
                        .addComponent(buttonCancelSwitch))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(selectorCbSNMP)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(boxSNMPVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(fieldNetworkName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(fieldCommunityName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(selectorSNMPWalkDump)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(fieldFilename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buttonFileSelect))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(buttonOK)
                            .addComponent(buttonCancel))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonAddSwitch)
                    .addComponent(buttonCancelSwitch))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void selectorCbSNMPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectorCbSNMPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_selectorCbSNMPActionPerformed

    private void buttonAddSwitchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddSwitchActionPerformed
        // TODO add your handling code here:
        System.out.println("Adding switch");
        currentSnmpAgent = new SnmpAgent();
        currentFileAgent = null;
        currentIndex++;
        listModel.add(currentIndex, currentSnmpAgent);
        setSNMPpartEnabled(true);
    }//GEN-LAST:event_buttonAddSwitchActionPerformed

    private void buttonCancelSwitchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelSwitchActionPerformed
        // TODO add your handling code here:
        System.out.println("Cancelling switch definition");
    }//GEN-LAST:event_buttonCancelSwitchActionPerformed

    private void setSNMPpartEnabled(boolean enabled) {
        selectorCbSNMP.setEnabled(enabled);
        boxSNMPVersion.setEnabled(enabled);
        fieldNetworkName.setEnabled(enabled);
        fieldCommunityName.setEnabled(enabled);
    }

    private void setDumpFilePartDisabled(boolean enabled) {
        selectorSNMPWalkDump.setEnabled(enabled);
        fieldFilename.setEnabled(enabled);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SwitchBase().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxSNMPVersion;
    private javax.swing.JButton buttonAddSwitch;
    private javax.swing.JButton buttonCancel;
    private javax.swing.JButton buttonCancelSwitch;
    private javax.swing.JButton buttonFileSelect;
    private javax.swing.JButton buttonOK;
    private javax.swing.JTextField fieldCommunityName;
    private javax.swing.JTextField fieldFilename;
    private javax.swing.JTextField fieldNetworkName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JCheckBox selectorCbSNMP;
    private javax.swing.JCheckBox selectorSNMPWalkDump;
    // End of variables declaration//GEN-END:variables

}
